const http = require("http");

const server = http.createServer();
server.on("listening", () => {
  console.log("Server is listening on port 3000");
});
server.on("request", (req, res) => {
  console.log("Request received: %s", req.url);
  console.log("Request received: %s", JSON.stringify(req.headers));
  console.log("Request received: %s", req.httpVersion);
  console.log("Request received: %s", req.method);
  res.setHeader("X-Foo", "bar");
  res.writeHead(200, { "Content-Type": "text/plain" });
  //   res.writeHead(200, { "Content-Type": "text/html" });
  res.write("Hello, World!");
  //   res.write("<h1>Hello, World!</h1>");
  res.end();
  //   res.end("<h1>hello</h1>");
});

server.on("error", (err) => {
  console.error("Error: %s", err.message);
});
server.listen(3000, "localhost");
